package com.breeze.mvxdemo.mvp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.breeze.mvxdemo.R;
import com.breeze.mvxdemo.bean.Account;

public class MVPActivity extends Activity implements MVPContract.IMVPView {
    private EditText mUserNameET;
    private TextView mResultTV;
    private MVPContract.IMVPPresenter mvpPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_normal);
        initView();
        mvpPresenter = new MVPPresenter(this);
    }

    private void initView() {
        mUserNameET = findViewById(R.id.userName);
        mResultTV = findViewById(R.id.result);
    }

    public void submit(View view) {
        String name = mUserNameET.getText().toString();
        mvpPresenter.getAccountData(name);
    }

    @Override
    public void showSuccessPage(Account account) {
        mResultTV.setText("用户账号：" + account.name + " | " + "用户等级：" + account.level);
    }

    @Override
    public void showFailedPage() {
        mResultTV.setText("获取数据失败");
    }
}
